package zhangcong.dao;

import org.springframework.transaction.annotation.Transactional;
import zhangcong.entity.ZhangCongEntity;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

import java.util.List;

@Component()
public class ZhangCongDao  extends HibernateDaoSupport {

    public List<ZhangCongEntity> queryPage(String name) {

        String sql = "select * from j03zhangcong where name like ? ";
        Query query=getSessionFactory().openSession().createSQLQuery(sql);
        query.setParameter(0,  "%" + name + "%");
        //将查询结果转成Map对象的集合
       // query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
       query.setResultTransformer(Transformers.aliasToBean(ZhangCongEntity.class));
        List<ZhangCongEntity> list=  query.list();

        return  list;
    }
    @Transactional
    public void save(ZhangCongEntity zhangCongEntity) {
        getSessionFactory().openSession().saveOrUpdate(zhangCongEntity);
    }
}
